package D1;

public class User implements Cloneable{
    private String id;
    private String username;
    private String password;
    private double[] score;

    public User() {
    }

    public User(String id, String username, String password, double[] score) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.score = score;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double[] getScore() {
        return score;
    }

    public void setScore(double[] score) {
        this.score = score;
    }
    //这是浅拷贝方式，拷贝出来的对象，封装的数据与元对象封装的数据一摸一样，引用类型拷贝的是地址
    //深拷贝方式：对象中基本数据类型直接拷贝，字符串类型的数据拷贝的还是地址，如果还包含其他对象，不会拷贝地址，会创建新的对象
    @Override
    protected Object clone() throws CloneNotSupportedException {
        //深拷贝方式：先克隆得到一个新对象
        User u = (User) super.clone();
        //再将新对象中的引用数据类型的数据，再次克隆
        u.score = u.score.clone();
        return super.clone();
    }
}
